// import { useEffect } from "@storybook/addons";
import React, { useEffect,useState} from "react";

function useDebounce (value : any , delay = 300) {
    const [debounceValue , setDebounceValue] = useState(value);

    useEffect(()=>{
        const handler = window.setTimeout(()=>{
            setDebounceValue(value);
        } , delay);
    
        return function(){
            clearTimeout(handler);
        }
    }, [value , delay]);

    return debounceValue;
}

export default useDebounce;